import request from '@/utils/request'
import { getToken } from '@/utils/auth'

export function getAll() {
  return request({
    url: '/lesson/all',
    method: 'get'
  })
}

export function add(clazz) {
  return request({
    url: '/lesson/append',
    method: 'post',
    data: {
      campus: clazz.campus,
      lessonFeature: clazz.lessonFeature,
      lessonImg: clazz.lessonImg,
      lessonInfo: clazz.lessonInfo,
      lessonName: clazz.lessonName,
      lessonPrice: clazz.lessonPrice,
      lessonState: clazz.lessonState,
      lessonType: clazz.lessonType,
      time: clazz.time + '小时/次',
      buyCount: clazz.buyCount
    }
  })
}

export function getById(id) {
  return request({
    url: '/lesson/',
    method: 'get',
    params: {
      id: id
    }
  })
}

export function getByCampusHeader() {
  return request({
    url: '/lesson/head',
    method: 'get',
    params: {
      head: getToken()
    }
  })
}

export function updateById(clazz) {
  return request({
    url: '/lesson/update',
    method: 'post',
    data: {
      lessonId: clazz.lessonId,
      campus: clazz.campus,
      lessonFeature: clazz.lessonFeature,
      lessonImg: clazz.lessonImg,
      lessonInfo: clazz.lessonInfo,
      lessonName: clazz.lessonName,
      lessonPrice: clazz.lessonPrice,
      lessonState: clazz.lessonState,
      lessonType: clazz.lessonType,
      time: clazz.time,
      buyCount: clazz.buyCount
    }
  })
}

export function deleteById(id) {
  return request({
    url: '/lesson/remove',
    method: 'post',
    data: {
      id: id
    }
  })
}

export function conditionSearch(search) {
  return request({
    url: '/lesson/mohu/condition/search',
    method: 'post',
    data: {
      campus: search.campus,
      lessonName: search.lessonName,
      maxPrice: search.maxPrice,
      minPrice: search.minPrice
      // userId: getToken()
    }
  })
}

export function conditionSearch2(search) {
  return request({
    url: '/lesson/mohu/condition/search',
    method: 'post',
    data: {
      campus: search.campus,
      lessonName: search.lessonName,
      maxPrice: search.maxPrice,
      minPrice: search.minPrice,
      userId: getToken()
    }
  })
}

export function conditionSearch3(search) {
  return request({
    url: '/lesson/mohu/condition/search',
    method: 'post',
    data: {
      campus: search.campus,
      lessonName: search.lessonName,
      maxPrice: search.maxPrice,
      minPrice: search.minPrice,
      orgId: search.orgId
    }
  })
}

export function mohuSearch(str) {
  return request({
    url: '/lesson/mohu/search',
    method: 'post',
    data: {
      str: str,
      userId: getToken()
    }
  })
}

export function getByOrg(orgId) {
  return request({
    url: '/lesson/all/orgId',
    method: 'get',
    params: {
      orgId: orgId
    }
  })
}
